<?php 
session_start();
$_SESSION['dict']="en-kh";
if(isset($_GET['submit'])){
	$_SESSION['keywords'] = $_GET['keywords'];	
	
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><?php echo $data['title']?> </title>
<link rel="stylesheet" href="site_media/css/styles.css" type="text/css" media="screen, projection" />
<script type="text/javascript" src="Site_media/js/jquery-1.6.4.js"></script>  
<script type="text/javascript" src="Site_media/js/javascript.js"></script>
<script type="text/javascript" src="Site_media/js/khmerkey.js"></script>
</head>

<body>
<h2>វចនានុក្រម</h2>
<div id="searchContainer"​ >
	<form action="<?php $_PHP_SELF ?>" method="GET">
			<label> 
				 <select name="selectDict">
			      <option value="en-kh">English-Khmer</option>
			      <option value="kh-kh">Khmer-Khmer</option>
			    </select>
			</label>
			<input id="field" name="keywords" type="text" value="<?php echo isset($_SESSION['keywords']) ? $_SESSION['keywords'] : "Search" ?>"/>
			<div id="delete"><span id="x">x</span></div>
			<input id="submit" name="submit" type="submit" value="Search" />		
	</form>
</div>
<?php 
if (isset($_GET["keywords"])){
	$suffix = "";
	
	// take the spacees out.and keep the html format,prevent sql injection
	$keywords = htmlentities(trim($_GET["keywords"]));
	if(empty($data['errors'])){
		//search : return array of result
		$results = $data['doc'];
		echo '<pre>';
		var_dump($results);
		echo '</pre>';
		$results_num = empty($results[0]) ? 0 : count($results);
		$suffix = 'លទ្ធផល';
		echo '<p> ស្វែងរកជាមួយពាក្យ <strong>',$keywords,'</strong> ទទួលបាន <strong>',$results_num,'</strong> ',$suffix,'</p>';
		
		/* display result */
		
		if(is_array($results) && sizeof($results)>=1){
							foreach ($results as $result) {
								echo '<p>
									<strong>'.$result['EN'].'</strong><br> ';
					}
		}
		 
		 
	}else{
		print_r($data['errors']);
	}
}
?>
<?php session_destroy(); ?>
</body>
</html>
